﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DataTransferObject;
using BusinnessLogicLayer;
using System.IO;
using System.Drawing.Imaging;

namespace PresentationLayer
{
    public partial class frmTeamDetail : DevExpress.XtraEditors.XtraForm
    {
        public byte[] logo_byte;
        public DTOTeam _dtoTeam = new DTOTeam();
        public BUSTeam _busTeam = new BUSTeam();
        DataTable dtTeam;

        public frmTeamDetail()
        {
            InitializeComponent();
            // This line of code is generated by Data Source Configuration Wizard
        }

        public frmTeamDetail(string seasonName, string teamID)
        {
            InitializeComponent();

            //disable button them
            bntAddInfo.Enabled = false;

            //load Team dua vao teamName va seasonName
            dtTeam = _busTeam.getTeamBySeasonNameAndTeamID(seasonName, teamID);

            //dien thong tin vao textbox
            txtName.Text = (dtTeam.Rows[0]["Name"]).ToString();
            txtID.Text = (dtTeam.Rows[0]["TeamID"]).ToString();
            txtCEO.Text = (dtTeam.Rows[0]["CEO"]).ToString();
            txtChairman.Text = (dtTeam.Rows[0]["Chairman"]).ToString();
            txtAddress.Text = (dtTeam.Rows[0]["Address"]).ToString();
            txtEmail.Text = (dtTeam.Rows[0]["Email"]).ToString();
            txtFax.Text = (dtTeam.Rows[0]["Fax"]).ToString();
            txtTel.Text = (dtTeam.Rows[0]["PhoneNumber"]).ToString();
            txtYear.Text = (dtTeam.Rows[0]["EstablishedYear"]).ToString();
            txtStadiumID.Text = (dtTeam.Rows[0]["StadiumID"]).ToString();
            txtStadiumName.Text = (dtTeam.Rows[0]["StadiumName"]).ToString();
            txtStadiumAddress.Text = (dtTeam.Rows[0]["Address1"]).ToString();
            txtTankage.Text = (dtTeam.Rows[0]["Tankage"]).ToString();
            byte[] logo = (byte[])(dtTeam.Rows[0]["Logo"]);
            MemoryStream memory = new MemoryStream(logo);
            Logo.Image = Image.FromStream(memory);

            //load cau thu
        }

        private void frmTeamDetail_Load(object sender, EventArgs e)
        {
           
        }

        private void Logo_EditValueChanged(object sender, EventArgs e)
        {

        }

        private void bntAddInfo_Click(object sender, EventArgs e)
        {

        }

        private void Logo_Click(object sender, EventArgs e)
        {
            openFileDialog1.ShowDialog();
            string url = openFileDialog1.FileName;
            if (string.IsNullOrEmpty(url))
                return;

            Image ima = Image.FromFile(openFileDialog1.FileName);
            MemoryStream stream = new MemoryStream();
            if (ima != null)
            {
                Logo.Image = ima;
                ima.Save(stream, ImageFormat.Jpeg);
                logo_byte = stream.ToArray();
            }
        }

        private void bntAddInfo_Click_1(object sender, EventArgs e)
        {
            DTOTeam _dtoTeam = new DTOTeam();
            BUSTeam _busTeam = new BUSTeam();

            _dtoTeam.name = txtName.Text.Trim();
            _dtoTeam.logo = logo_byte;
            _dtoTeam.address = txtAddress.Text.Trim();
            _dtoTeam.chairman = txtChairman.Text.Trim();
            _dtoTeam.cEO = txtCEO.Text.Trim();
            _dtoTeam.email = txtEmail.Text.Trim();
            _dtoTeam.fax = txtFax.Text.Trim();
            _dtoTeam.stadiumID = "ST0002";
            _dtoTeam.phoneNumber = txtTel.Text.Trim();
            _dtoTeam.teamID = "T00002";
            _dtoTeam.establishedYear = txtYear.Text.Trim();

            if (_busTeam.insertTeam(_dtoTeam) > 0)
            {
                MessageBox.Show("Them Thanh cong");
            }
        }


    }
}